#!/usr/sbin/rsct/perl5/bin/perl 
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 1999,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# "@(#)29   1.21   src/rsct/registry/cli/bin/selectsr.perl, srcli, rsct_rpyxh, rpyxht1f3 2/22/01 16:25:42
######################################################################
#                                                                    #
# Module: selectsr                                                   #
#                                                                    #
# Purpose:                                                           #
#   selectsr - Select (display) information from a System Registry   #
#              table.                                                #
#                                                                    #
# Syntax:                                                            #
#   Current Usage:                                                   #
#   selectsr[-h][-l|i|d|D Delimiter][-s][-fr Result_table][-x][-TV]  #
#               Table `Selection_string' [Column...]                 #
#                                                                    #
#   Future Usage:                                                    #
#   selectsr[-h][-l|i|d|D Delimiter][-k Sort_key][-s]                #
#               [-fr Result_table][-x][-TV] Table `Selection_string' #
#               [Column...]                                          #
#                                                                    #
# Flags:                                                             #
#   -h  Help. Writes this command's usage statement to stdout.       #
#   -l  Long form output. Metadata descriptions included in output.  #
#   -i  Input file format. Display output in a format suitable for   #
#       use as input to mksrrow.                                     #
#   -d  Delimiter formatted output. The default delimiter is a colon #
#       ":", use the -D flag if you wish to change the default       #
#       delimiter.                                                   #
#   -D Delimiter                                                     #
#       Delimiter formatted output using the specified delimiter.    #
#       Use this flag to specify something other than the default    #
#       colon ":", when the data to be displayed may contain colons. #
#       Use this flag to specify a one or more character delimiter.  #
#   -k Sort_key                                                      #
#       Displays the output of the select sorted (ascending) on the  #
#       given column. Sort_key must be an existing column in the     #
#       table.                                                       #
#   -s  Print System (SY-qualified) columns.                         #
#   -f  Force overwrite. If saving the result table (using the -r    #
#       flag, this flag forces any existing System Registry table    #
#       of the same name to be overwritten.                          #
#   -r Result_table                                                  #
#       Name of a new table to save the result of the select to.     #
#       Result_table  can be an absolute or relative path name.      #
#   -x  Exclude header. Suppress header printing.                    #
#   -T  Trace. Writes this command's trace messages to stderr.       #
#   -V  Verbose. Writes this command's verbose messages to stderr.   #
#                                                                    #
# Operands:                                                          #
#   Table   The name of the table you wish to retrieve (select)      #
#           information from. An absolute or relative path name can  #
#           be used.                                                 #
#   Result_table  Optional. The name of the table you wish to save   #
#           the selected table to. An absolute or relative path can  #
#           be used. The parent directory of the Result_table must   #
#           already exist.                                           #
#   Selection_string Search criteria for the select. (See BNF Grammar#
#           description in the srcli manpage.) (See Examples section #
#           for common usage.)                                       #
#   Column  Optional. Name of the column you wish to have displayed. #
#           Zero or more Column operands can be specified.           #
#                                                                    #
# Description:                                                       #
#   The selectsr command selects table information from a table Table#
#   in the System Registry based on user defined criteria,           #
#   optionally displaying the results or creating a new private      #
#   table. Refer to the current System Registry C API document for   #
#   the BNF Grammar definition for valid Selection_strings.          #
#                                                                    #
#   Columns displayed are defined by the list of Columns as given on #
#   the command line. If no column names are given, all are returned.#
#                                                                    #
#   The result of the select is displayed by default in tabular form #
#   using headers. Hexadecimal characters are used to display binary #
#   data. Use any of the [- l|i|d|D Delimiter][-s]and[ -x ] flags to #
#   alter the output. NOTE: The [ -x ] and [ -l|i] flags can not be  #
#   used simultaneously.  If they are, the [ -x ] flag is ignored.   #
#   See the Examples section for output samples.                     #
#                                                                    #
#   Unless the -r flag is specified and a Result_table name given,   #
#   the result table is discarded after being written to standard    #
#   out. A table name must be supplied with this flag. Table names   #
#   must be unique to the containing directory. For a list of tables #
#   in the current working directory, use the lssr command.          #
#                                                                    #
#   Future Usage:                                                    #
#   Output of the select is ordered as it exists in the table unless #
#   the -k Sort_key flag is used. In this case, the result table is  #
#   sorted in ascending order on the column name given by Sort_key.  #
#   The column name given must exist in the result table. Sorts can  #
#   be performed on user-defined and system-defined columns. Use the #
#   lssrtbldef command for a list of the current columns in the      #
#   table.                                                           #
#                                                                    #
# Exit Values:                                                       #
#   0  SR_CLI_SUCCESS        Command completed successfully.         #
#   1  SR_CLI_REGISTRY_ERROR Command terminated due to an underlying #
#                            System Registry error.                  #
#   2  SR_CLI_ERROR          Command terminated due to an underlying #
#                            error in the command script.            #
#   3  SR_CLI_BAD_OPERAND    Command terminated due to user          #
#                            specifying a bad operand.               #
#   4  SR_CLI_BAD_FLAG       Command terminated due to user          #
#                            specifying an invalid flag.             #
#   5  SR_CLI_USER_ERROR     Command terminated due to a user error. #
#                            For example specifying an undefined     #
#                            table to be selected on.                #
#                                                                    #
# Examples:                                                          #
#   selectsr /IBM/Subnet/Subnets 'SubnetID?=*.64'                    #
#   - displays all columns of all rows with SubnetID ending in '.64' #
#   in the table /IBM/Subnet/Subnets.                                #
#                                                                    #
#   selectsr -dx /IBM/Node/Nodes 'NodeNumber==3' NodeID NodeNumber   #
#   - displays the entire contents of /temp/table2 using colon       #
#   delimiters and no headers                                        #
#                                                                    #
#   selectsr -ls /IBM/Node/Nodes 'NodeID>99 AND NodeName?=*.ibm.com' #
#   - displays all rows of table /IBM/Node/Nodes using a compound    #
#   condition, output is in long format and includes System columns. #
#                                                                    #
#   selectsr -r sub.tmp /IBM/Subnet/Subnets 'SubnetID?=9.114.85.* OR #
#                  SubnetID?=9.114.16.*'                             #
#   - stores all rows of the table /IBM/Subnet/Subnets to the AIX    #
#   file sub.tmp in the current AIX working directory. An            #
#   OR connected compound condition is applied to the data before    #
#   saving. If the AIX file exists, it will not be overwritten.      #
#                                                                    #
#--------------------------------------------------------------------#
# Inputs:                                                            #
#   from command line                                                #
#                                                                    #
# Outputs:                                                           #
#   stdout - displaying table resulting from select and help         #
#   stderr - displaying verbose, trace and error messages            #
#                                                                    #
# External Ref:                                                      #
#   Commands: $LSMSG                                                 #
#   Extensions:  CT::SR.pm CT::SRrc.pm CT::CT.pm                     #
#   Perl library routines: Getopts::Std                              #
#   SR cli library:  SR_cli_utils - init_session, isRelative,        #
#                               printCEMsg, save_result_table        #
#                               set_session_variables clean_session  #
#                    SR_cli_display_utils - create_display           #
#                    SR_cli_Risplay_utils - create_display           #
#                                                                    #
# Tab Settings:                                                      #
#   4 and tabs should be expanded to spaces before saving this file. #
#   in vi:  (:set ts=4  and   :%!expand -4)                          #
#                                                                    #
# Change Activity:                                                   #
#   000929 HGJ 38317: Initial delivery.                              #
#                                                                    #
######################################################################

#--------------------------------------------------------------------#
#                                                                    #
# General Program Logic/Flow:                                        #
#                                                                    #
# A: Parse command line - determine selection criteria and columns   #
#    to be returned from table given.                                #
# B: Initialize session with registry, including setting the         #
#    current directory setting depending on whether an absolute or   #
#    relative table name was given.                                  #
# C: Attempt to open table to be selected from - report error if     #
#    unsuccessful.                                                   #
# D: Call CT::SR::select  - report on success or failure             #
# E: Display table information as requested by input line flags.     #
# F: Clean up session table and tree.                                #
#                                                                    #
#--------------------------------------------------------------------#


#--------------------------------------------------------------------#
# Included Libraries                                                 #
#--------------------------------------------------------------------#
use lib "/usr/sbin/rsct/pm";
use locale;
use Getopt::Std;

use CT::CT qw(:ct_data_type_t);
use CT_cli_utils qw(printIMsg
                    printEMsg
);

use CT::SR;
use CT::SRrc;
use SR_cli_utils qw(init_session    isRelative      
                    printCEMsg      save_result_table printCIMsg
                    $DEFAULT_GLOBAL_MOUNT_POINT     open_table
                    clean_session   set_session_variables
                    error_exit
);
use SR_cli_display_utils qw(create_display);
use SR_cli_rc qw(:return_codes);


#--------------------------------------------------------------------#
# Global Variables                                                   #
#--------------------------------------------------------------------#
# Constants for use throughout the program
$TRUE            = 1;
$FALSE           = 0;

# Initialise defaults for output options 
$Opt_Long_Output = $FALSE;           # see -l flag ($opt_l)
$Opt_File_Output = $FALSE;           # see -i flag ($opt_i)
$Opt_Delimiter   = $FALSE;           # see -d, -D flags ($opt_d,$opt_D)
$Opt_Save_Overwrite = $FALSE;        # see -f flag ($opt_f)
$Opt_Save        = $FALSE;           # see -r flag ($opt_r)
$Opt_Print_SY    = $FALSE;           # see -s flag ($opt_s)
$Opt_Print_Key   = $TRUE;            # $FALSE if columns given
$Opt_No_Header   = $FALSE;           # see -x flag ($opt_x)
$Trace           = $FALSE;           # see -T flag ($opt_T)
$Verbose         = $FALSE;           # see -V flag ($opt_V)

# Message map variables
$PROGNAME        = "selectsr";       # Program Name for messages
$MSGCAT          = "srcli.cat";      # msg catalogue for this cmd
$CTDIR           = "/usr/sbin/rsct"; # Cluster directory path
$CTBINDIR        = "$CTDIR/bin";     # Cluster Bin directory path
$LSMSG           = "$CTBINDIR/ctdspmsg"; # Display message rtn.
$ENV{'MSGMAPPATH'} = "$CTDIR/msgmaps";   # Msg maps path for $LSMSG

%Cleanup = ();                       # Hash of items to cleanup
                                     # {Session} $session to term

#--------------------------------------------------------------------#
# Variables                                                          #
#--------------------------------------------------------------------#
# Initialise the Perl extension (Class) variables used in the program
my $Table_handle    = "";
my $Result_table    = CT::SR::table_handle_t->new;

# These are fed into initSession
my $Tree_handle     = "";

# Assign column names to be at least as big as the number
# of input arguments. This should be more than adequate.
my @Column_names    = ();

my $rc              = 0;               # assume good return code
my $Set_work_dir    = $FALSE;
my $Table           = "";
my $Table_name      = "";
my $Select_string   = "";
my $Columns_returned = "";


#--------------------------------------------------------------------#
# Main Code                                                          #
#--------------------------------------------------------------------#
# TODO: Many verbose statements in this code will eventually by
# Trace statements when the facility is available as a Perl CLI
# (feature 48401)
# TODO: security on access to the table can not be further defined
# until after a security design has been implemented for the SR.
# ( feature 48402 ) Until then, the table is opened with the
# minimum security necessary to complete the command.
# TODO: FFDC handling will be implemented in Feature 48397.


# Parse the command line, exit if there are errors
($rc, $Table_name, $Select_string, @Column_names) = parse_cmd_line();
($rc == 0) || error_exit($rc);

# Echo command line input if Verbose flag set
if ($Verbose) {
    if ($Columns_returned ne "") {
        $Command_line_input = sprintf "\"\n  %s\n  %s\n  %s\"", 
                        $Table_name, $Select_string, 
                        $Columns_returned;
    }
    else {
        $Command_line_input = sprintf "\"\n  %s\n  %s\n  %s\"", 
                        $Table_name, $Select_string;
    }
    printIMsg("IMsgselectsrCommandLineInput", $Command_line_input);
}


# Establish registry session if possible. Change current directory if 
# a relative table name given, using value set in CT_SR_HOME.
$holder = 0;
$holder2 = 0;
if ($Opt_Save) {
    ($holder, $Save_table_name) = 
                        set_session_variables($Opt_Save);
}

($holder2, $Table) = set_session_variables($Table_name);
if ($holder || $holder2) { $Set_work_dir = $TRUE; }

($rc,$Tree_handle) = init_session($Set_work_dir);
($rc == 0) || error_exit($rc);

# Add the tree handle to the cleanup hash
$Cleanup{Session} = $Tree_handle;

$Verbose && 
    printIMsg("IMsgselectsrSelectTable", $Table_name, $Table);


# Open table to be selected on. If there's an error, close
# gracefully by ending the registry session and exiting.
($rc, $Table_handle) = open_table($Tree_handle, $Table,
                        $Table_name, SR_METADATA);
($rc == 0) || error_exit($rc);

# Add this table handle to the cleanup hash
push @{$Cleanup{Tables}}, $Table_handle;


# Call CT::SR::select extension to attempt to get the result table

$Trace && print STDERR "Calling CT::SR::select\n";
$rc = CT::SR::select($Table_handle, \@Column_names, scalar(@Column_names), 
                        $Result_table, $Select_string);
$Trace && print STDERR "CT::SR::select return code: $rc\n";

# Check the return code from CT::SR::select
$rc = error_check("sr_select", $rc, $Table_name);
($rc == 0) || error_exit($rc);


# Add the result table to the cleanup hash
push @{$Cleanup{Tables}}, $Result_table;


# If table is to be saved, save and exit. Otherwise 
# display the result table depending on input flags given
if ($Opt_Save) {
    $rc = save_result_table($Result_table, $Save_table_name, 
                $Opt_Save_Overwrite);
}
elsif ($Opt_Long_Output) {
    # Long form output
    $rc = create_display($Result_table, $Table_name, "long", 
                $Opt_Delimiter, $Opt_No_Header, $Opt_Print_SY,
                $Opt_Print_Key, \@Column_names);
}
elsif ($Opt_File_Output) {
    # Input file format printed - one row per line
    $rc = create_display($Result_table, $Table_name, "file", 
                $Opt_Delimiter, $Opt_No_Header, $Opt_Print_SY,
                $Opt_Print_Key, \@Column_names);
}
elsif ($Opt_Delimiter) {
    # Colon-separated output
    $rc = create_display($Result_table, $Table_name, "delim", 
                $Opt_Delimiter, $Opt_No_Header,  $Opt_Print_SY,
                $Opt_Print_Key, \@Column_names);
}
else {
    # Column output by default
    $rc = create_display($Result_table, $Table_name, "column",
                $Opt_Delimiter, $Opt_No_Header, $Opt_Print_SY,
                $Opt_Print_Key, \@Column_names);
}


# Clean session up and exit, even if display failed 
# If display/select failed then preserve the error code. Will be
# more thoroughly handled in the FFDC feature.
($rc == 0) || error_exit($rc);

$rc = clean_session($Tree_handle, $Mount_point, $Table_handle, 
                        $Result_table );
($rc == 0) || error_exit($rc);

# Exit with the least non-zero return code
exit $rc;

#--------------------------------------------------------------------#
# End Main Code                                                      #
#--------------------------------------------------------------------#


#--------------------------------------------------------------------#
# parse_cmd_line:                                                    #
#   Uses getopts to collect flags and input from command line        #
#   continuing to parse any remaining data in @ARGV. Name of table   #
#   to be edited is passed back to calling program.                  #
#   This subroutine will exit if it finds an error.                  #
#                                                                    #
# Return values:                                                     #
#   $local_rc      - local return code                               #
#   $table_name    - name of table to be selected from               #
#   $select_string - selection criteria                              #
#   $return_string - list of columns to be returned by select        #
#   @column_names  - (optional)                                      #
#                                                                    #
# Global Variables Altered:                                          #
#   $Opt_Long_Output   output   True (-l) request long format output.#
#   $Opt_File_Output   output   True (-i) request input file format  #
#                               output.                              #
#   $Opt_Delimiter     output   Delimiter string (-d | -D delim_str) #
#                               when -d delimit str set to :         #
#   $Opt_Print_SY      output   True (-s) request printing System    #
#                               columns.                             #
#   $Opt_No_Header     output   True (-x) request header suppression #
#                               in output.                           #
#   $Opt_Force_Overwrite output True (-f) overwrite existing table.  #
#                               when saving result table.            #
#   $Opt_Save          output   True (-r) save result table          #
#   $Trace             output   True (-T) turn Trace mode on.        #
#   $Verbose           output   True (-V) turn Verbose mode on.      #
#--------------------------------------------------------------------#
sub parse_cmd_line
{
my $done           = 0;
my $local_rc       = 0;
my $table_name     = "";
my $select_string  = "";
my $return_string  = "";
my $entry          = "";
my $select         = 0;
my $key            = "";
my $value       = "";
my @col_names   = ();
my %opts = ();

# Get input flags, if any - exit if incorrect flag given
if (getopts('hlidD:fr:sxTV', \%opts) == 0) {        
    printCEMsg("EMsgSRcliInvalidFlag");
    print_usage();
    return SR_CLI_BAD_FLAG;
}

# Help option given - ignore rest of command line 
if (defined $opts{h}) {   # print usage and exit
    print_usage();
    exit(0);
}

# Set Trace global if requested
if (defined $opts{T}) {
    $Trace = $TRUE;
}

# Set Verbose global if requested
if (defined $opts{V}) {
    $Verbose = $TRUE;
}

# Save Result table
if (defined $opts{r}) {
    $Opt_Save = $opts{r};
}

# Overwrite existing table with Save Result table (Force save)
if (defined $opts{f}) {
    $Opt_Save_Overwrite = $TRUE;
}

# Suppress header printing
if (defined $opts{x}) { 
    $Opt_No_Header = $TRUE; 
}

# Print (mksrrow) input file formatted output
if (defined $opts{i}) { 
    $Opt_File_Output = $TRUE; 
}

# Row Change Counter suppress flag
if (defined $opts{s}) { 
    $Opt_Print_SY = $TRUE; 
}

# String delimited output
if (defined $opts{D}) { 
    $Opt_Delimiter = $opts{D}; 
}

# Colon delimited output
if (defined $opts{d}) { 
    $Opt_Delimiter = ":";
}

# Long form output
if (defined $opts{l}) { 
    $Opt_Long_Output = $TRUE; 
}

# If nothing else on command line, print error message and quit 
if (!@ARGV) {
    printCEMsg("EMsgSRcliNoTableName");
    print_usage();
    return SR_CLI_BAD_OPERAND;
}

$table_name = shift @ARGV;

# If no selection string given, then print error message and quit
if (!@ARGV) { 
    printCEMsg("EMsgSRcliNoSelectionString");
    print_usage();
    return SR_CLI_BAD_OPERAND;  
}

# If code gets to here, there is at least a selection string to
# pick up. It is supposed to be enclosed in quotes, so next
# shift picks it up from ARGV.
$select_string = shift @ARGV;

# If nothing is left in ARGV, return all the columns in the table
if (!@ARGV) {  
    return ($local_rc, $table_name, $select_string);
}
else {  
    # Put each of the column names into the $Column_names 
    # structure for passing to CT::SR::select.
    # Also save a regular string containing the column names
    # for later display
    my $index = 0;

    # Put the rest of @ARGV into the column to be displayed string
    $Opt_Print_Key = $FALSE;
    foreach (@ARGV) { 
        $col_names[$index++] = $_;
        $return_string .= $_."  ";
    }
}
return ($local_rc ,$table_name, $select_string, @col_names);
}   # end parse_cmd_line


#--------------------------------------------------------------------#
# error_check:                                                       #
#   Checks the return code from the SR function.  If an error is     #
#   detected appropriate error messages will be displayed and        #
#   SR CLI return code set.                                          #
#                                                                    #
# Parameters:                                                        #
#   $sr_function  - Name of the SR function that was called and      #
#                   whose error code we are checking.                #
#   $sr_rc        - SR function return code.                         #
#   $table_name   - Name of the SR table.                            #
#                                                                    #
# Return values:                                                     #
#   None.                                                            #
#                                                                    #
# Global References:                                                 #
#   None.                                                            #
#--------------------------------------------------------------------#
sub error_check
{
my ($sr_function, $sr_rc, $table_name) = @_;
my $rc = 0;

if ($sr_rc != 0) { 
    if ($sr_rc == SR_NO_PERMISSION) {
        printEMsg("EMsgselectsrNoPermission", $table_name);
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_CONNECTION_LOST) {
        printCEMsg("EMsgSRcliConnectionLost");
        $rc = SR_CLI_REGISTRY_ERROR;
    }
    elsif ($sr_rc == SR_NO_TABLE) {
        printEMsg("EMsgselectsrNoTableReturned");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_NO_COLUMN) {
        printEMsg("EMsgselectsrNoColumn", $table_name);
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_COL_TYPE_ERROR) {
        printEMsg("EMsgselectsrColTypeError");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_UNMATCHING_PARENTHESIS) {
        printCEMsg("EMsgSRcliSEUnmatchingParen");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_NO_COLUMN) {
        printCEMsg("EMsgSRcliSENoColumn");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_COLUMN_NAME) {
        printCEMsg("EMsgSRcliSEIllegalColumnName");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_INVALID_TYPE_VARIABLE) {
        printCEMsg("EMsgSRcliSEInavlidTypeVar");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_UNMATCHING_TYPE_VARIABLE) {
        printCEMsg("EMsgSRcliSEUnmatchingTypeVar");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_INVALID_OPERATOR) {
        printCEMsg("EMsgSRcliSEInvalidOperator");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_INVALID_COMPARISON) {
        printCEMsg("EMsgSRcliSEInvalidComparison");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_SELECTION_STRING) {
        printCEMsg("EMsgSRcliSEIllegalSS");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_EXTRA_CHARS) {
        printCEMsg("EMsgSRcliSEExtraChars");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_NO_VAR_PARAMETER) {
        printCEMsg("EMsgSRcliSENoVarParameter");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_RANGE) {
        printCEMsg("EMsgSRcliSEIllegalRange");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_RANGE_LIST) {
        printCEMsg("EMsgSRcliSEIllegalRangeList");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_STRING_CONSTANT) {
        printCEMsg("EMsgSRcliSEIllegalStringConst");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_NULL_STRING_CONSTANT) {
        printCEMsg("EMsgSRcliSENullStringConst");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_NUMERIC_CONSTANT) {
        printCEMsg("EMsgSRcliSEIllegalNumericConst");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_NULL_NUMERIC_CONSTANT) {
        printCEMsg("EMsgSRcliSENullNumericConst");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_SE_ILLEGAL_REGEX) {
        printCEMsg("EMsgSRcliSEIllegalRegex");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc == SR_NULL_POINTER) {
        printCEMsg("EMsgSRcliSSNullPointer");
        $rc = SR_CLI_USER_ERROR;
    }
    elsif ($sr_rc < 0) {
        # TODO: temporary check for selection string errors:
        # Waiting on code from SR C API
        print STDERR "selectsr: selection string error\n";
        $rc = SR_CLI_USER_ERROR;
    }
    else {
        printEMsg("EMsgselectsrErrorSelectingTable", $table_name,
            $sr_rc);
        printCEMsg("EMsgSRcliSRCommandFailure", $sr_function, $sr_rc);
        $rc = SR_CLI_REGISTRY_ERROR;
    }
}

return ($rc);
}   # end error_check


#--------------------------------------------------------------------#
# print_usage : print the usage statement (syntax) to stdout.        #
#   See this command's prologue syntax section for current usage.    #
#--------------------------------------------------------------------#
sub print_usage
{
printIMsg("IMsgselectsrUsage");
}   # end print_usage


#--------------------------------------------------------------------#
#   End File                                                         #
#--------------------------------------------------------------------#
